cmake_minimum_required(VERSION 3.10)
project(abc-server)

cmake_policy(SET CMP0077 NEW)

set(CMAKE_CXX_STANDARD 20)
set(BUILD_SHARED_LIBS OFF)
# 设置搜索库时尝试添加的前缀，分号用于分割字符串，表示需要尝试添加lib前缀和添加空字符串前缀（即无前缀）
set(CMAKE_FIND_LIBRARY_PREFIXES "lib;")


find_package(Python3 REQUIRED)
message(STATUS "Python3 Executable: [${Python3_EXECUTABLE}]")

message(STATUS "Preparing third libs")
execute_process(
    COMMAND ${Python3_EXECUTABLE} tools/prepare.py ${CMAKE_SOURCE_DIR}
    WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
)

message(STATUS "Building web resources")
execute_process(
    COMMAND ${Python3_EXECUTABLE} ${CMAKE_SOURCE_DIR}/web/tools/build.py ${CMAKE_SOURCE_DIR}/web
    WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
)

if(MSVC)
    add_compile_options(/MD$<$<CONFIG:Debug>:d>)
endif()

if(CMAKE_COMPILER_IS_GNUCXX)
    link_libraries(-lstdc++fs)
endif()


add_subdirectory(src)


set_target_properties(
    abc-server
    PROPERTIES
        LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/out$<CONFIG>"
        RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/out$<CONFIG>"
)

if(MSVC)
    file(COPY "${CMAKE_SOURCE_DIR}/tools/win32/pack.bat" DESTINATION ${CMAKE_BINARY_DIR})
    file(COPY "${CMAKE_SOURCE_DIR}/tools/win32/repack.bat" DESTINATION ${CMAKE_BINARY_DIR})
    file(COPY "${CMAKE_SOURCE_DIR}/tools/win32/build.bat" DESTINATION ${CMAKE_BINARY_DIR})
    file(COPY "${CMAKE_SOURCE_DIR}/tools/win32/rebuild.bat" DESTINATION ${CMAKE_BINARY_DIR})
endif()
